package demo.yangxu.springcloud.alibaba.controller;

import demo.yangxu.springcloud.alibaba.domain.CommonResult;
import demo.yangxu.springcloud.alibaba.service.AccountService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
public class AccountController {
    @Resource
    private AccountService accountService;
    //请求方式要与2001中的AccountService一致
    //想取巧的话可以写
    //@RequestMapping("/account/decrease")
    //交给Spring MVC自动判断
    @PostMapping(value = "/account/decrease")
    public CommonResult decrease(@RequestParam("userId") Long userId,@RequestParam("money") BigDecimal money){
        accountService.decrease(userId, money);
        return new CommonResult(200,"扣减账户余额成功！");
    }
}
